package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.InfoNotice;
import com.hs.service.InfoNoticeService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("InfoNotice")
public class InfoNoticeController {
    @Autowired
    private InfoNoticeService infoNoticeService;
    @PostMapping
    public R addInfoNotice(@RequestBody InfoNotice infoNotice) {
        int i = infoNoticeService.addInfoNotice(infoNotice);
        if (i>0){
            return R.ok();
        }else{
            return R.fail("增加失败");
        }
    }
    @DeleteMapping("{id}")
    public R deleteInfoNotice(@PathVariable int id) {
        int i = infoNoticeService.deleteInfoNotice(id);
        if (i>0){
            return R.ok();
        }else{
            return R.fail("删除失败");
        }
    }
    @PutMapping
    public R updateInfoNotice(@RequestBody InfoNotice infoNotice) {
        int i = infoNoticeService.updateInfoNotice(infoNotice);
        if (i>0){
            return R.ok();
        }else{
            return R.fail("修改失败");
        }
    }
    @GetMapping("page")
    public R getInfoNoticeByPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                                 @RequestParam(required = false,defaultValue = "2") int pageSize) {
        PageInfo<InfoNotice> infoNoticeByPage = infoNoticeService.getInfoNoticeByPage(pageNum, pageSize);
        return R.ok(infoNoticeByPage);
    }
}
